package com.czy.ekp.util;

import java.util.HashMap;
import java.util.List;

/**
 * 通用返回结果集
 */
public class ResultMap extends HashMap {

    private boolean success;
    private String code;
    private String message;
    private Object data;

    public ResultMap() {

    }

    public ResultMap(ResultEnum resultEnum) {
        this.success = ResultEnum.SUCCESS.getCode().equals(resultEnum.getCode());
        this.code = resultEnum.getCode();
        this.message = resultEnum.getmessage();
        this.put("success", success);
        this.put("message", message);
        this.put("code", code);
    }

    public ResultMap(boolean success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.put("success", success);
        this.put("message", message);
        this.put("code", code);
    }

    public static ResultMap success(){
        return new ResultMap(ResultEnum.SUCCESS);
    }

    public static ResultMap success(String message){
        return new ResultMap(ResultEnum.SUCCESS).setMessage(message);
    }

    public static ResultMap failure(){
        return new ResultMap(ResultEnum.FAILURE);
    }

    public static ResultMap failure(String message){
        return new ResultMap(ResultEnum.FAILURE).setMessage(message);
    }


    public boolean isSuccess() {
        return success;
    }

    public ResultMap setSuccess(boolean success) {
        this.success = success;
        this.put("success", success);
        return this;
    }

    public String getCode() {
        return code;
    }

    public ResultMap setCode(String code) {
        this.code = code;
        this.put("code", code);
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResultMap setMessage(String message) {
        this.message = message;
        this.put("message", message);
        return this;
    }

    public Object getData() {
        return data;
    }

    public ResultMap setData(Object data) {
        this.data = data;
        this.put("data", data);
        return this;
    }
}
